package com.ls.dal;
import java.util.Date;
import com.google.common.collect.Maps;

//import com.ls.modules.sys.dal.mybatis.dao.DemoMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ls.base.utils.PageUtils;
import com.ls.base.utils.Query;
import com.ls.modules.sys.dal.mongodb.dao.PersonRepository;
import com.ls.modules.sys.dal.mongodb.entity.PersonEntity;
import com.ls.modules.sys.dal.mybatis.dao.UserMapper;
import com.ls.modules.sys.dal.mybatis.entity.UserEntity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: xiaosu
 * @date: 2018-09-20  17:12
 */

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@EnableAutoConfiguration
public class SampleDao {


    @Autowired
    private UserMapper userMapper;

    @Autowired
    private PersonRepository personRepository;

    @Test
    public void testSelect() {
        System.out.println(("----- selectAll method test ------"));
        Map<String,Object>  params=new HashMap<>();



        params.put("page","2");
        params.put("limit","10");
        String paramKey = (String)params.get("name");
//        Page<UserEntity> page = new Page<UserEntity>(roleParam.getPi().intValue(), roleParam.getPs().intValue());


        IPage<UserEntity>  page=userMapper.selectPage(new Query(params).getPage(), new QueryWrapper<UserEntity>().like("name","o"));

        PageUtils pageUtils=  new PageUtils(page);

        System.out.println(page.getTotal()+"ssssssss");



        List<UserEntity> userList = userMapper.selectList(new QueryWrapper<UserEntity>().like("name","ack"));
//        Assert.assertEquals(5, userList.size());
        userList.forEach(System.out::println);
    }



    //    public PageUtils queryPage(Map<String, Object> params) {
//        String paramKey = (String)params.get("name");
//
//
//
////        Page<DemoEntity> page = this.baseMapper.selectPage(
////                new Query<DemoEntity>(params).getPage(),
////                new QueryWrapper<DemoEntity>()
////                        .like(StringUtils.isNotBlank(paramKey),"name", paramKey)
////        );
//
////        return new PageUtils(page);
//        return  null;
//    }

//    @Autowired
//    private DemoMapper demoDao;
//
//    @Test
//    public void testSelect() {
//        System.out.println(("----- selectAll method test ------"));
//        List<DemoEntity> userList = demoDao.selectList(null);
//        System.out.println(userList);
////
////        Assert.assertEquals(5, userList.size());
////        userList.forEach(System.out::println);
//    }


    @Test
    public void TestSave(){
        PersonEntity  entity=new PersonEntity();
        entity.setName("xiaosu");
        entity.setAge(20);
        entity.setGender(true);



        personRepository.save(entity);
        System.err.println("保存成功！");
    }

    /**
     * 查询全部User实体
     */
    @Test
    public void TestFindAll(){
        List<PersonEntity> users = personRepository.findAll();
        System.err.println("size: "+users.size()+","+users.get(0).getName());
    }


    /**
     * 根据name查询User
     */
    @Test
    public void TestFindByName(){
        List<PersonEntity> users = personRepository.findByName("appleyk");
        System.err.println("size: "+users.size());
    }

    /**
     * 根据id删除对应User实体
     */
    @Test
    public void TestDelete(){
        personRepository.deleteAll();
        System.err.println("删除成功！");
    }



}
